1. Field of the Invention
The present invention relates to a moving image coding apparatus and a moving image coding method. More particularly, the present invention relates to a technique suitably used to code moving image data based on a coding method such as H.264.
2. Description of the Related Art
In recent years, video cameras that can record high definition (HD) images using a disk medium, a hard disk, or a memory as a recording medium have been commercially available. Such video cameras can record high-quality video images, while being compact and easy to carry. In view of the above, use of the video cameras is expected to become increasingly widespread in the future. In the video cameras, in order to efficiently record HD images, a video stream compressed and coded using MPEG 4 Part-10: AVC (ISO/IEC 14496-10, known as H.264) is recorded in a recording medium.
A summary of the compression procedure according to the H.264 method is described in detail in the ISO/IEC 14496-10 standard. Further, an image processing apparatus that performs compression and coding processing using the H.264 method is discussed, for example, in Japanese Patent Application Laid-Open No. 2006-217180.
In the H.264 method, in performing the compression and coding, a target code amount is adjusted to an assumed virtual video buffering verifier (VBV) (hereinafter, referred to as virtual buffer). The virtual buffer is defined based on a code generation amount in an entropy-coding and an output code amount.
Further, in the H.264 method, as the entropy-coding method, two types of methods are provided and can be selected. The one is context-based adaptive variable length coding (CAVLC) method based on Huffman code. The other method is context-based adaptive binary arithmetic coding (CABAC) method that uses an arithmetic coding. Especially, the CABAC method emphasizes coding efficiencies, and calculation amounts are large. Accordingly, in the CABAC method, the coding processing requires a lot of time.
The H.264 method is often used to code HD images of 1920×1080 (pixels). Accordingly, as compared to images of a standard definition (SD) of 720×480 (pixels), the number of pixels to be processed in the HD image is six times larger than that in the SD image. Accordingly, in order to code the HD image in real time without increasing the operating frequency, it is required to perform the coding operation in multi-core processing. In view of the above, it is preferable to perform a quantization processing and an entropy-coding processing in synchronization with each other on a picture-by-picture basis. However, it is difficult to perform the entropy-coding processing in multi-core processing because of its characteristic in the processing. Accordingly, the entropy-coding processing and the quantization processing may be performed asynchronously.
In such a case, an entropy-coding of a preceding picture and a quantization of a current picture may be concurrently performed. Accordingly, especially in the CABAC method, when CABAC processing of the preceding picture is finished, a quantization of a succeeding picture has been often started or completed.
Further, in such a case, an actually generated code amount of the preceding picture can be larger than an assumed code amount and an underflow can occur in the virtual buffer. The occurrence of the underflow in the virtual buffer can be found when the CABAC processing of the preceding picture is finished. Then, the coding has already been finished. To solve the problem, in the H.264 method, when the underflow occurs in the virtual buffer, the underflowed picture is replaced with a copy picture.
FIG. 5A is a schematic view illustrating an example when an underflow occurs in a virtual buffer. FIG. 5B is a schematic view illustrating an example of an occupancy of a virtual buffer when an underflowed picture is replaced with a copy picture. A transition of the occupancy in a case where a picture being code-processed is replaced with a copy picture is described with reference to FIGS. 5A and 5B.
If the occupancy becomes lower than a minimum position for a size of a virtual buffer, an underflow occurs in the virtual buffer. As illustrated in FIG. 5A, when the underflow occurs in the virtual buffer, processing to replace a coding target picture (underflowed picture) at that time with a copy picture is performed. By the replacement processing, the occupancy transits to the one as illustrated in FIG. 5B, and a stream breakup and a buffer breakup can be prevented.
FIG. 6 is a schematic view illustrating timing of quantization processing and entropy-coding processing in a case where both processing is asynchronously performed. Processing timing in quantization processing and entropy-coding processing is described with reference to FIG. 6.
In FIG. 6, when a picture is input on a frame-by-frame or a field-by-field basis, processing is performed for each picture in order of quantization processing and entropy-coding processing. However, the timing of the quantization processing and the entropy-coding processing is asynchronous. Therefore, while an entropy-coding processing of a first picture 601 is being performed, entropy-coding processing of a second picture 602, a third picture 603, and a fourth picture 604, which are succeeding pictures, can be performed.
As described above, in the case where the underflow occurs in the virtual buffer and the picture being code-processed is replaced with the copy picture, the quantization processing of the succeeding pictures have been started while the entropy-coding processing of the picture is being performed. Accordingly, if the picture as to which the underflow occurs in the virtual is a reference picture that is referred to in an inter picture prediction, the following problems can occur. Because the reference picture is replaced with the copy picture, the already quantized succeeding pictures perform erroneous motion compensations. Thus, when the pictures are decoded, an error may occur, and the deteriorated image may be displayed. Further, at the time the underflow occurs in the virtual buffer, the quantization processing of the succeeding pictures have already been started. Accordingly, it is difficult to perform the quantization processing of the succeeding pictures again by using the replaced copy picture as a new reference picture to continue the real-time coding of the moving image.